<template>
  <div class="container">
    <van-nav-bar
      title="我的订单"
      left-arrow
      left-text="返回"
      @click-left="Order"
    >
    </van-nav-bar>

    <div class="content img-list">
      <div v-for="(item, index) in OrderList" :key="index" class="content-item">
        <img
          :src="item.picUrl"
          style="height: 140px; margin-top: 10px"
        />
        <span
          style="
            margin-top: 5px;
            font-size: 13px;
            display: flex;
            justify-content: center;
          "
          >{{ item.name }}</span
        >
        <div style="display: flex; justify-content: space-between">
          <span style="color: red; font-size: 15px">{{
            "￥" + item.price
          }}</span>
          <span style="font-size: 15px">支付成功</span>
        </div>

        <van-button @click="deleteOrder" type="danger"> 删除 </van-button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from "vant";
export default {
  data() {
    return {
      OrderList: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      axios({
        url: "http://127.0.0.1:3000/users/order/list",
        method: "get",
      }).then((res) => {
          console.log("订单", res.data);
          this.OrderList=res.data
       
      });
    },
    //删除订饭
    deleteOrder() {
      axios({
        url: "http://127.0.0.1:3000/index/Orderdelete",
        method: "get",
        params: {
          ...this.OrderList,
        },
      }).then((res) => {
        Toast.success("删除成功");

        this.getData();
      });
    },
    Order() {
      this.$router.go(-1);
    },
  },
};
</script>
<style scope lang='scss'>
.container {
  background: #fafafa;

  .img-list {
    flex-wrap: wrap;
    img {
      height: 50px;
      width:  150px;
    }
  }
  .content {
    display: flex;
    width: 100%;
    .content-item {
      display: flex;
      flex-direction: column;
      width: 50%;
      // height: 250px;
      padding: 10px;
      box-sizing: border-box;
    }
  }
}
</style>